/*
 * @描述: 
 * @创建者: kilomChou
 * @Date: 2021-05-14 21:28:14
 * @最后编辑: kilomChou
 * @LastEditTime: 2021-05-15 14:08:25
 */
import Player from "../../player/Player";
import BaseWorldManager from "./BaseWorldManager";

/** 世界玩家管理器 */
export default class WorldPlayerMgr extends BaseWorldManager {

    /** 玩家映射 <玩家id,玩家> */
    readonly playerMap = new Map<number, Player>();

    start() {

    }

    update() {

    }

    /** 创建玩家 */
    createPlayer(name: string, addToWorld = true) {
        let player = new Player(this.world, name);
        addToWorld && this.addPlayer(player);
        return player;
    }

    /** 添加玩家到世界 */
    addPlayer(player: Player) {
        this.world.snakeMgr.addSnake(player.snake);
        this.playerMap.set(player.id, player);
        return player;
    }

    /** 从世界中移除玩家 */
    removePlayer(player: Player) {
        this.world.snakeMgr.removeSnake(player.snake);
        this.playerMap.delete(player.id);
    }

}